<!--
    设备状态日志明细
 -->
<template>
    <div class="page">
        <div class="nuclein-query">
            <div>设备状态日志明细</div>
            <div style="margin-left: auto;">
                <!-- <el-button type="primary" @click="handlerAdd()">添加</el-button> -->
            </div>
        </div>

        <div class="content-row">
            <el-table :data="tableData" style="width: 100%" border>
                <el-table-column label="序号" prop="name">
                </el-table-column>
                <el-table-column label="设备名称" prop="name">
                </el-table-column>
                <el-table-column label="设备编号" prop="phone">
                </el-table-column>
                <el-table-column label="设备所在小区" prop="comeAddress">
                </el-table-column>
                <el-table-column label="设备SN" prop="comeAddress">
                </el-table-column>
                <el-table-column label="设备类型" prop="acidTime">
                </el-table-column>
                <el-table-column label="设备动作" prop="acidTime">
                </el-table-column>
                <el-table-column label="上线/下线时间" prop="acidTime">
                </el-table-column>
                <el-table-column label="状态" prop="acidTime">
                    <tag>
                        <!-- 下线 -->
                        <!-- 上线 -->
                    </tag>
                </el-table-column>
                <el-table-column label="操作" align="center" width="160">
                    <template slot-scope="scope">
                        <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger"
                            @click="handleDelete(scope.$index, scope.row.id)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <div class="pagination">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
                :page-sizes="[10, 20, 30, 40]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>

        <div>
            <el-dialog title="添加" :visible.sync="dialogFormVisible">
                <el-form :model="form">
                    <el-form-item label="姓名" :label-width="formLabelWidth">
                        <el-input v-model="form.name" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="联系方式" :label-width="formLabelWidth">
                        <el-input v-model="form.phone" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="来访地址" :label-width="formLabelWidth">
                        <el-input v-model="form.comeAddress" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="最近核酸时间" :label-width="formLabelWidth">
                        <el-date-picker v-model="form.acidTime" type="datetime" placeholder="请选择">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="新到人员到访时间" :label-width="formLabelWidth">
                        <el-date-picker v-model="form.newPeopleBeginTime" type="datetime" placeholder="请选择">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="新到人员离开时间" :label-width="formLabelWidth">
                        <el-date-picker v-model="form.newPeopleEndTime" type="datetime" placeholder="请选择">
                        </el-date-picker>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取 消</el-button>
                    <el-button type="primary" @click="Submite">确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</template>

<script>
import { getPeopleManage, addPeopleManage } from '../../api/api'
import commonFunction from '../../utils/commonFunction'
export default {

  data () {
    return {
      dialogFormVisible: false,
      form: {
        name: '',
        phone: '',
        comeAddress: '',
        acidTime: '',
        newPeople: '',
        newPeopleBeginTime: undefined,
        newPeopleEndTime: undefined
      },
      total: 10,
      page: 1,
      limit: 10,
      formLabelWidth: '160px',
      tableData: [],
      search: ''
    }
  },
  created () {
    this.gitList()
  },
  methods: {
    // 获取
    gitList () {
      const data = {
        type: 'newPeople',
        bool: true,
        page: this.page,
        limit: this.limit
      }
      getPeopleManage({ data }).then(res => {
        if (res.code == 200) {
          const { totalCount, list } = res.data
          this.tableData = list
          this.total = totalCount
        }
      })
    },

    Submite () {
      const data = {
        id: this.form.id ? this.form.id : null,
        name: this.form.name,
        phone: this.form.phone,
        comeAddress: this.form.comeAddress,
        acidTime: commonFunction.getTimeFormat(+new Date(this.form.acidTime), 'YYYY-MM-DD'),
        isolate: false,
        newPeople: true,
        newPeopleBeginTime: commonFunction.getTimeFormat(+new Date(this.form.newPeopleBeginTime), 'YYYY-MM-DD'),
        newPeopleEndTime: commonFunction.getTimeFormat(+new Date(this.form.newPeopleEndTime), 'YYYY-MM-DD'),
        diagnosis: false,
        touch: false
      }
      addPeopleManage(data).then(res => {
        if (res.code == 200) {
          this.form = {
            name: '',
            phone: '',
            comeAddress: '',
            acidTime: '',
            newPeople: '',
            newPeopleBeginTime: undefined,
            newPeopleEndTime: undefined
          }
          this.$message.success(data.id != null ? '编辑成功' : '添加成功')
          this.gitList()
          this.dialogFormVisible = false
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    handlerAdd () {
      this.form = {
        name: '',
        phone: '',
        comeAddress: '',
        acidTime: '',
        isolate: '',
        isolateBeginTime: undefined,
        isolateEndTime: undefined,
        isolateAddress: undefined
      }
      this.dialogFormVisible = true
    },
    handleEdit (index, row) {
      this.dialogFormVisible = true
      this.form = {
        id: row.id,
        ...row
      }
    },
    handleDelete (index, row) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const data = {
          id: row,
          isDelete: true
        }
        addPeopleManage({ ...data }).then(res => {
          if (res.code == 200) {
            this.$message.success('删除成功')
            this.gitList()
          } else {
            this.$message.error(res.msg)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 分页
    handleSizeChange (val) {
      this.limit = val
      this.gitList()
    },
    handleCurrentChange (val) {
      this.page = val
      this.gitList()
    }
  }
}
</script>

<style scoped>
.page {
    position: relative;
    height: 100%;
}

.nuclein-query {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    border-bottom: 1px solid #DCDFE6;
}

.content-row {
    overflow: hidden;
}

/* 分页 */
.pagination {
    width: 100%;
    padding: 20px;
    border-top: 1px solid #DCDFE6;
}
</style>
